package com.idanchuang.support.etcache.remote;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Objects;

/**
 * 用来将原始Key封装为远程缓存的key对象
 *
 * @author yjy
 * Created at 2021/12/22 4:44 下午
 */
public class RemoteKey implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 缓存名称, 等于 cacheName
     */
    private String cn;
    /**
     * 是否压测缓存, 0否 1是
     */
    private int pressure;
    /**
     * 原始Key的编码数据
     */
    private byte[] kbs;

    public RemoteKey() {
    }

    public RemoteKey(String cacheName, int pressure, byte[] keyBytes) {
        this.cn = cacheName;
        this.pressure = pressure;
        this.kbs = keyBytes;
    }

    public int getPressure() {
        return pressure;
    }

    public void setPressure(int pressure) {
        this.pressure = pressure;
    }

    public String getCn() {
        return cn;
    }

    public void setCn(String cn) {
        this.cn = cn;
    }

    public byte[] getKbs() {
        return kbs;
    }

    public void setKbs(byte[] kbs) {
        this.kbs = kbs;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        RemoteKey remoteKey = (RemoteKey) o;
        return pressure == remoteKey.pressure
                && Objects.equals(cn, remoteKey.cn)
                && Arrays.equals(kbs, remoteKey.kbs);
    }

    @Override
    public int hashCode() {
        int result = Objects.hash(cn, pressure);
        result = 31 * result + Arrays.hashCode(kbs);
        return result;
    }
}
